/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.sBean;

import com.aptech.entities.TblOrder;
import java.util.Date;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Winner
 */
@Stateless
public class TblOrderFacade extends AbstractFacade<TblOrder> {

    @PersistenceContext(unitName = "Elevation_System_Online-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public TblOrderFacade() {
        super(TblOrder.class);
    }

    public List<TblOrder> getOrderByUserID(int usID) {
        Query query = em.createNamedQuery("TblOrder.findByUser");
        query.setParameter("usID", usID);
        return query.getResultList();
    }
     public List<TblOrder> getOrderByStatus() {
        Query query = em.createNamedQuery("TblOrder.findByOdStatus");       
        return query.getResultList();
    }

//    public List<TblOrder> Statistic(String month) {
//        Query query = em.createQuery("SELECT t FROM TblOrder t WHERE  t.odCreated LIKE '%-10-%'");
//        query.setParameter("month", month);         
//        return query.getResultList();
//    }
    public int Statistic(String month) {
        Query query = em.createQuery("SELECT SUM(t.odToatl) FROM TblOrder t WHERE  t.odCreated LIKE :month");
        query.setParameter("month", "%-" + month + "-%");
        return query.hashCode();
    }
    public List<TblOrder> getOrderByOdID(int odID) {
        Query query = em.createNamedQuery("TblOrder.findByOdID");
        query.setParameter("odID", odID);
        return query.getResultList();
    }
    //statistic
    public List<TblOrder> getTblOrderByDateOdCreated(Date dateStart,Date dateEnd) {
        Query query = em.createNamedQuery("TblOrder.findByDateOdCreated");
        query.setParameter("dateStart", dateStart);
        query.setParameter("dateEnd", dateEnd);
        return query.getResultList();  
    }
}
